! Configuration File for keepalived

global_defs {
   router_id {{ ansible_facts['default_ipv4']['address'] }}
}

vrrp_instance VI_1 {
    state MASTER
    interface {{ ansible_facts['default_ipv4']['interface'] }}
    virtual_router_id 51
    {% if ansible_facts['default_ipv4']['address'] == hostvars['servera']['ansible_facts']['default_ipv4']['address'] %}
priority 100
    {% elif ansible_facts['default_ipv4']['address'] == hostvars['serverb']['ansible_facts']['default_ipv4']['address'] %}
priority 99
    {% endif %}
advert_int 1
    authentication {
        auth_type PASS
        auth_pass {{ auth_pass }}
    }
    virtual_ipaddress {
         {{ ansible_facts['default_ipv4']['address'].split('.')[:3] | join('.') }}.{{ virtual_ip }}
    }
}

